/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.DrawController;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;

/**
 *
 * @author Jasper
 */
public class ImagePanel extends javax.swing.JPanel implements MouseListener, MouseMotionListener{
    //TODO
    // ONDERSCHEID TSS TEKENAAR EN RADER
    // ZORGEN VOOR REAL TIME TEKENEN

/**
 * to add backgroundimage to a panel
 */

    int xPressed,yPressed;
    int xReleased,yReleased;
    int xDragged,yDragged;
    private List<Point> points = new ArrayList<Point>();

    // instance variables
    private DrawController drawController;
    

    public ImagePanel(DrawController drawController) {
        setPreferredSize(new Dimension(1280, 700));
        setBounds(0, 0, 1280, 700);
        setBackground(Color.WHITE);
        addMouseListener(this);
        addMouseMotionListener(this);
        this.drawController = drawController;
    }

    @Override
    public void paintComponent(Graphics g) {

        super.paintComponents(g);
        for(int i = 0; i < points.size() - 2; i++){
            Point p1 = points.get(i);
            Point p2 = points.get(i + 1);
            //g.drawLine(p1.x, p1.y, p2.x, p2.y);
            g.drawOval(p1.x, p1.y, 1, 3);
        }
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    @Override
    public void mouseClicked(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        xPressed = e.getX();
        yPressed = e.getY();
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        xReleased = e.getX();
        yReleased = e.getY();
        
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseDragged(MouseEvent e) {
//        Graphics g = getGraphics();
//        xDragged = xPressed;
//        yDragged = yPressed;
//        g.drawLine(xPressed, yPressed, e.getX(), e.getY());
//        xDragged = e.getX();
//        yDragged = e.getY();
        points.add(e.getPoint());
        repaint();
        drawController.updateFrame(points);
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
}